<?php

/**
 * @package Nina
 * @author John Main <john@thedaddy.org>
 */
class Nina_Model_Migration extends Nina_Model
{
	/*! Table name (required) */
	const TABLE_NAME = "migrations";
	
	/*! PK field (required) */
	const ID = "migrations.id";
	
	/*! Table fields */
	const INDEX = "migrations.index";
	const CORE = "migrations.core";
	const CREATED_AT = "migrations.created_at";
	const UPDATED_AT = "migrations.updated_at";
	
	/**
	 * Get the indexes of all the already run migrations
	 * @param boolean [$core=true] Get core migration records
	 * @return array
	 */
	public static function get($core = true) {
		$already_run = array();

		$c = self::newCriteria();
		$c->add(self::CORE, $core);
		$c->addOrderBy(self::INDEX, Nina_Orm_Criteria::ORDER_ASC);
		foreach(self::doSelect(new self(), $c) as $migration) {
			$already_run[] = $migration->getIndex();
		}
		
		return $already_run;
	}
}